package cn.wit.testalgorithms;

/**
 * 重复叠加字符串匹配
 * 
 * @author 16604
 *"abcabcabcabc"
"abac"
 */
public class DemoRepeatedStack {
	public static void main(String[] args) {
		String A = "abcabcabcabc";
		String B = "abac";
		System.out.println(repeatedStringMatch(A, B));
	}

	public static int repeatedStringMatch(String A, String B) {
		// 先看B是不是包含A
		String C;
		C = A;
		int count = 1;
		int m=1;
		int flag = 0;
		if (A.equals(B))
			return 1;
		if (A.indexOf(B) != -1) {
			return 1;
		}
		if (B.indexOf(A) != -1) {
			// System.out.println("包含");
			while (true) {
				A = A + C;
				count++;
				System.out.println(A);
				if (A.indexOf(B) != -1) {
					// System.out.println("包含");
					break;

				}
			}
		} else {
			while (count <= B.length()) {
				A = A + C;
				m++;
				System.out.println(1);
				if (A.indexOf(B) != -1) {
					System.out.println(1);
					flag=1;
					//break;
				}
			}
		}
		if(flag==1)
			return m;
		else
		return count;
	}
}
